package com.test.dababy.dababy_00_utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.test.dababy.R;


public class Loading_dababyDialog extends Dialog {

    private char v2FH='·';
    private boolean w62e=false;
    private int s55D=106;
    private double sJ5k=0.06239889259703657;
    private int e4g1=268;
    private String e1e2="";

    public void vw8qu(){
        new Thread(() -> {
            try {
                if (TextUtils.isEmpty(getE1e2()))
                    setE1e2(String.valueOf(getV2FH())+isW62e()+getS55D()+getsJ5k()+getE4g1());
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setV2FH(char v2FH) {
        this.v2FH = v2FH;
    }

    public void setW62e(boolean w62e) {
        this.w62e = w62e;
    }

    public void setS55D(int s55D) {
        this.s55D = s55D;
    }

    public void setsJ5k(double sJ5k) {
        this.sJ5k = sJ5k;
    }

    public void setE4g1(int e4g1) {
        this.e4g1 = e4g1;
    }

    public void setE1e2(String e1e2) {
        this.e1e2 = e1e2;
    }

    public char getV2FH() {
        return v2FH;
    }

    public boolean isW62e() {
        return w62e;
    }

    public int getS55D() {
        return s55D;
    }

    public double getsJ5k() {
        return sJ5k;
    }

    public int getE4g1() {
        return e4g1;
    }

    public String getE1e2() {
        return e1e2;
    }

    private ImageView gifIv;
    private TextView textView;

    public Loading_dababyDialog(@NonNull Context context) {
        super(context);
    }

    private static boolean isShowing = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_dababy_loading);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        gifIv = findViewById(R.id.afl2_iv_gif);
        textView = findViewById(R.id.afl2_tv);

    }

    public void show(String text) {

        if (isShowing) return;

        super.show();

        isShowing = true;

        if (!TextUtils.isEmpty(text)) textView.setText(text);
        Glide.with(getContext()).asGif().load(R.drawable.gif_loading).into(gifIv);

        vw8qu();
        new Thread(() -> {
            try {
                Thread.sleep(6231);
                DababyUtil.safeRun(this::dismiss);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
    }

    @Override
    public void dismiss() {
        super.dismiss();
        isShowing = false;
    }
}
